﻿using System;
using Bricks.Logging;

namespace Motar.Web.Mvc
{

    /// <summary>
    /// 
    /// </summary>
    public class MvcInitializer : ApplicationInitializerBase
    {

        /// <summary>
        /// 
        /// </summary>
        /// <param name="containerFacade"></param>
        public MvcInitializer(Bricks.Injecting.IContainerFacade containerFacade, ILoggerFacade loggerFacade) :
            base(containerFacade)
        {
            if (loggerFacade == null)
            {
                throw new ArgumentNullException("loggerFacade");
            }
            _loggerFacade = loggerFacade;
        }

        /// <summary>
        /// 
        /// </summary>
        private readonly ILoggerFacade _loggerFacade;

        /// <summary>
        /// 
        /// </summary>
        public ILoggerFacade LoggerFacade
        {
            get { return _loggerFacade; }
        }

        /// <summary>
        /// 
        /// </summary>
        public override void Execute()
        {
            ConfigureDependencyResolver();
        }

        /// <summary>
        /// 
        /// </summary>
        protected virtual void ConfigureDependencyResolver()
        {
            Execute(containerFacade => System.Web.Mvc.DependencyResolver.SetResolver(containerFacade.Resolve<System.Web.Mvc.IDependencyResolver>()));
        }
    }
}
